package com.homework;

//1.计算器接口具有work方法，功能是运算，有一个手机类Cellphone,
//定义方法testWork测试计算功能，调用计算接口的work方法
//2.要求调用Cellphone对象的testWork方法，使用上匿名内部类

public class Homework03 {
    public static void main(String[] args) {
        Cellphone cellphone = new Cellphone();
        cellphone.testWork(new ICalculate(){
            @Override
            public double work(double n1,double n2){
                return n1 + n2;
            }
        },10,8);
    }

}

interface ICalculate{
    public double work(double n1,double n2);

}

class Cellphone {
    //当调用testWork方法时，直接传入一个实现了ICalculate接口的匿名内部类即可
    //该匿名内部类，可以灵活的实现work，完成不同的计算任务
    public void testWork(ICalculate iCalculate,double n1,double n2){

        double result = iCalculate.work(n1,n2);
        System.out.println("计算的结果是 " + result);
    }
}